﻿@page "/So/SaleDetail/Edit"
@using nERP.ViewModel.So.SaleDetailVMs
@using System.ComponentModel.DataAnnotations
@inherits BasePage

<div>
    <ValidateForm @ref="vform" Model="@Model" OnValidSubmit="@Submit">
        <Row ItemsPerRow="ItemsPerRow.Three" RowType="RowType.Normal">
            <BootstrapInput @bind-Value="@Model.Entity.Seq" />
            <Select @bind-Value="@Model.Entity.SaleId" Items="AllSales" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" Id="g9bb5b3140c1c43d9be6402aa0d9ec6d3" />
            <BootstrapInput @bind-Value="@Model.Entity.SaleDetailCode" />
            <Select @bind-Value="@Model.Entity.GoodsId" Items="AllGoodss" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" Id="g1ed1a7b5ab004f8ba71c3cbad311bac1" />
            <BootstrapInput @bind-Value="@Model.Entity.GoodsName" />
            <BootstrapInput @bind-Value="@Model.Entity.GoodsSpec" />
            <BootstrapInput @bind-Value="@Model.Entity.GoodsUnit" />
            <BootstrapInput @bind-Value="@Model.Entity.SaleNumber" FormatString="0.##" />
            <BootstrapInput @bind-Value="@Model.Entity.UnitPrice" FormatString="0.##" />
            <BootstrapInput @bind-Value="@Model.Entity.TotalPrice" FormatString="0.##" />
            <BootstrapInput @bind-Value="@Model.Entity.DiscountPrice" FormatString="0.##" />
            <BootstrapInput @bind-Value="@Model.Entity.TaxRate" FormatString="0.##" />
            <BootstrapInput @bind-Value="@Model.Entity.TaxUnitPrice" FormatString="0.##" />
            <BootstrapInput @bind-Value="@Model.Entity.TaxPrice" FormatString="0.##" />
            <BootstrapInput @bind-Value="@Model.Entity.TotalTaxPrice" FormatString="0.##" />
            <BootstrapInput @bind-Value="@Model.Entity.Remark" />
        </Row>

        <div class="modal-footer table-modal-footer">
            <Button ButtonType="ButtonType.Submit" IsAsync="true" Text="@WtmBlazor.Localizer["Sys.Submit"]" />
            <Button OnClick="OnClose" Text="@WtmBlazor.Localizer["Sys.Close"]" />
        </div>

    </ValidateForm>

</div>



@code {
    [Parameter]
    public string id { get; set; }
    [Parameter]
    public string[] ids { get; set; }
    private SaleDetailVM Model = new SaleDetailVM();
    private ValidateForm vform { get; set; }
    private async Task Submit(EditContext context)
    {


        await PostsForm(vform, "/api/So/SaleDetail/Edit", (s) => "Sys.OprationSuccess", method: HttpMethodEnum.PUT);
    }
    public void OnClose()
    {
        CloseDialog();
    }

    private List<SelectedItem> AllSales = new List<SelectedItem>();
    private List<SelectedItem> AllGoodss = new List<SelectedItem>();
    protected override async Task OnInitializedAsync()
    {


        AllSales = await WtmBlazor.Api.CallItemsApi("/api/So/SaleDetail/GetSales");
        AllSales.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllGoodss = await WtmBlazor.Api.CallItemsApi("/api/So/SaleDetail/GetGoodss");
        AllGoodss.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        if (id != "")
        {
            var rv = await WtmBlazor.Api.CallAPI<SaleDetailVM>($"/api/So/SaleDetail/{id}");
            Model = rv.Data;
        }

        await base.OnInitializedAsync();
    }
}
